package com.example.supernote.ui.components

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ImageSearch
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.supernote.ui.theme.SuperNoteTheme


@Composable
fun UniformButton(
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    onClick: () -> Unit,
    imageVector: ImageVector? = null,
    contentDescription: String = "",
    text: String? = null,
) {
    Button(
        enabled = enabled,
        onClick = onClick,
        modifier = modifier.border(
            1.dp, MaterialTheme.colorScheme.primary, RoundedCornerShape(10.dp)
        ),
        colors = ButtonColors(
            containerColor = MaterialTheme.colorScheme.surface,
            contentColor = MaterialTheme.colorScheme.primary,
            disabledContainerColor = MaterialTheme.colorScheme.surface,
            disabledContentColor = MaterialTheme.colorScheme.secondary,
        ),
        contentPadding = PaddingValues(start = 5.dp, end = 5.dp)
    ) {
        Row(verticalAlignment = Alignment.CenterVertically) {
            if (imageVector != null) UniformIcon(
                modifier = Modifier.height(24.dp),
                imageVector = imageVector,
                contentDescription = contentDescription
            )
            if (text != null) Text(
                text = text, color = MaterialTheme.colorScheme.primary
            )
        }
    }
}


@Composable
fun UniformIcon(
    modifier: Modifier = Modifier,
    imageVector: ImageVector,
    contentDescription: String = "",
) {
    Icon(
        modifier = modifier.size(24.dp),
        imageVector = imageVector,
        contentDescription = contentDescription,
        tint = MaterialTheme.colorScheme.primary
    )
}


@Preview(showBackground = true)
@Composable
fun PreviewIconButton() {
    SuperNoteTheme(darkTheme = true) {
        UniformButton(
            onClick = { /*TODO*/ }, imageVector = Icons.Filled.ImageSearch, text = "hhhhh"
        )
    }
}